package net.sunbeta.testng;

import java.io.File;
import java.io.FileFilter;

import javax.servlet.ServletContext;

public class WebContainer {

    public static Class[] scan(ServletContext context) {
        String root = context.getRealPath("/WEB-INF/classes");
        ClassScanner scanner = new ClassScanner(new File(root));
        scanner.setLoader(ClassScanner.class.getClassLoader());
        // we pick a specific directory
        final File testsDir = new File(root, "net.sunbeta.test");
        scanner.setFilter(new FileFilter() {

            public boolean accept(File pathname) {
                return pathname.getPath().startsWith(testsDir.getPath());
            }
        });
        Class[] classes = scanner.getClasses();
        return classes;
    }
}
